define(["jquery", "admin_base"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'curd.table/index',
        add_url: 'curd.table/add',
        edit_url: 'curd.table/edit',
        delete_url: 'curd.table/delete',
        modify_url: 'curd.table/modify',
        export_url: 'curd.table/export',
        password_url: 'curd.table/password',
        field_url:"curd.table/fieldlist",
    };
   var  initlist = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
       index_url: 'curd.table/fieldlist',
       add_url: 'curd.table/addfiled',
    };
    var Controller = {

        index: function () {

            ea.table.render({
                init: init,
                cols: [[
                    { type: "checkbox" },
                    { field: 'id', width: 80, title: 'ID' },
                    {
                        field: 'TABLE_NAME', width: 100, title: '表名', edit: 'text'
                    },
                    { field: 'ENGINE', minWidth: 80, title: '引擎' },
                    { field: 'TABLE_ROWS', minWidth: 80, title: '总记录数' },
                    { field: 'TABLE_COLLATION', minWidth: 80, title: '字符集' },
                    { field: 'TABLE_COMMENT', minWidth: 80, title: '说明' },
                    { field: 'CREATE_TIME', minWidth: 80, title: '创建时间', search: 'range' },
                    {
                        width: 250,
                        title: '操作',
                        templet: ea.table.tool,
                        operat: [[ {
                            text: '字段',
                            url: init.field_url,
                            field: 'id',
                            method: 'open',
                            extend: 'data-full="true"',
                            auth: 'stock',
                            class: 'layui-btn  layui-btn-xs layui-btn-normal',
                        }, {
                            title: '确定删除？',
                            text: '删除表',
                            field: 'id',
                            url: init.delete_url,
                            method: 'delete',
                            class: 'layui-btn layui-btn-danger layui-btn-xs',
                        },],]
                    }
                ]],
            });

            ea.listen();
        },
        fieldlist:function(){
            ea.table.render({
                init: initlist,
                where: { id: $("input[name='cate_id']").val() },
                toolbar: ['refresh', [{
                    text: '添加',
                    url: initlist.add_url,
                    method: 'open',
                    auth: 'add',
                    class: 'layui-btn layui-btn-normal layui-btn-sm',
                    icon: 'fa fa-plus ',
                    extend: 'data-full="true"',
                }],],
                cols: [[
                    { type: "checkbox" },
                    {
                         width: 80, title: '序号', type: 'numbers'
                    },
                    { field: 'COLUMN_NAME', minWidth: 80, title: '列名' ,edit: true },
                    { field: 'IS_NULLABLE', minWidth: 80, title: '是否必填',selectList: { 'YES': '否', 'NO': '是' }  ,edit: true },
                    { field: 'DATA_TYPE', minWidth: 80, title: '数据类型',templet:ea.table.selects },
                    { field: 'CHARACTER_MAXIMUM_LENGTH', minWidth: 80, title: '长度', edit: true },
                    { field: 'COLUMN_DEFAULT', minWidth: 80, title: '默认值', edit: true },
                    { field: 'COLUMN_KEY', minWidth: 80, title: '索引', edit: true },
                    { field: 'COLUMN_COMMENT', minWidth: 80, title: '备注' },
                    { field: 'DATETIME_PRECISION', minWidth: 80, title: '排序' },
                    {
                        width: 250,
                        title: '操作',
                        templet: ea.table.tool,
                        operat: [[{
                            text: '保存',
                            url: init.field_url,
                            field: 'id',
                            method: 'open',
                            auth: 'stock',
                            class: 'layui-btn  layui-btn-xs layui-btn-normal',
                        }, {
                            title: '确定删除？',
                            text: '删除字段',
                            field: 'id',
                            url: init.delete_url,
                            method: 'delete',
                            class: 'layui-btn layui-btn-danger layui-btn-xs',
                        },],]
                    }
                ]],
            });
            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        }
    };
    return Controller;
});